package com.lxhll.personnel.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.lxhll.personnel.core.ResponseData;
import com.lxhll.personnel.entity.ResignEmployee;
import com.lxhll.personnel.service.EmployeeService;
import com.lxhll.personnel.service.ResignEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * (ResignEmployeeDao.xml)表控制层
 * 离职员工信息表
 *
 * @author makejava
 * @since 2021-07-24 10:15:43
 */
@RestController
@RequestMapping("/resign")
public class ResignEmployeeController extends ApiController {
    /**
     * 服务对象
     */
    @Autowired
    private ResignEmployeeService resignEmployeeService;
    @Autowired
    private EmployeeService employeeService;
    /**
     * 分页查询所有离职员工
     *分页对象,查询参数集合
     * @param params
     * @return 所有数据
     */
    @PostMapping("/list")
    public ResponseData list(@RequestBody Map<String,Object> params) {
        IPage<Map<String,Object>> list=resignEmployeeService.resignList(params);
        return ResponseData.ok(list);
    }

    /**
     * 通过离职表主键查询详细信息己其员工
     *
     * @param resign_id 主键
     * @return 单条数据
     */
    @GetMapping("/info/{resign_id}")
    public ResponseData info(@PathVariable Integer resign_id) {
        ResignEmployee resignEmployee=resignEmployeeService.getById(resign_id);
        int employeeId=resignEmployee.getEmployeeId();
        resignEmployee.setEmployee(employeeService.getResignEmployeeById(employeeId));
        return ResponseData.ok(resignEmployee);
    }

    /**
     * 新增离职数据
     *
     * @param resignEmployee 实体对象
     * @return 新增结果
     */
    @PostMapping("/save")
    public ResponseData insert(@RequestBody ResignEmployee resignEmployee) {
        //员工离职信息添加
        resignEmployeeService.saveResign(resignEmployee);
        return ResponseData.ok();
    }
    
}
